# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=wai-middleware-static
pkgname=haskell-wai-middleware-static
pkgver=0.9.2
pkgrel=210
pkgdesc="WAI middleware that serves requests to static files"
url="https://github.com/scotty-web/wai-middleware-static"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-base16-bytestring' 'haskell-cryptohash-sha1'
         'haskell-expiring-cache-map' 'haskell-http-types' 'haskell-mime-types'
         'haskell-old-locale' 'haskell-wai')
makedepends=('ghc' 'uusi' 'haskell-hspec' 'haskell-hspec-discover'
             'haskell-hspec-expectations-lifted' 'haskell-hspec-wai' 'haskell-mockery'
             'haskell-scotty' 'haskell-wai-extra')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('fbfb57a64b9eabce3196c97a1727a533d9dc71fdf3e3a2316e6eb5edffc26b7c7f091b0ebc9144c129d3ec6bc452ddb846ef15e898d62507b4170f5354188be8')

prepare() {
    cd $_hkgname-$pkgver
    uusi -d semigroups $_hkgname.cabal
}

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
